const {
    toUrl,
    globalData
} = getApp()
import {
    request,
    baseUrl
} from '@/utils/request'
Page({
    toUrl,
    data: {
        content: '',
        globalData,
        title: '',
        typeTitle: 18,
        html:''
    },

    onLoad(e) {
        this.setData({
            html:'<div>hello word</div>'
        })
        console.log(e);
        let {
            title,
            ids
        } = e
        console.log(title);
        let id = 1
        if (title) {
            if (title.includes('注册')) {
                id = 2
            }
            if (title.includes('积分')) {
                id = 3
            }
            if (title.includes('停车')) {
                id = 4
            }
            if (title.includes('升级')) {
                id = 5
            }
            if (title.includes('营销')) {
                id = 6
            }
            if (title.includes('栏目')) {
                // id = 1
                this.getBannerList(ids)
                return
            }
            if (title.includes('签到')) {
                
                id = 9
            }

        }
        wx.setNavigationBarTitle({
            title
        })
        request('currency/getarticle', {
            data: {
                id
            }
        }).then(({
            data
        }) => {
            const {
                title,
                content
            } = data
            wx.setNavigationBarTitle({
                title
            })
            let zhengze = new RegExp('<img', 'g')
            let contents = content.replace(zhengze, '<img style="width:100%;height:auto;display:block;margin:10px 0;" ')
      
            if (content.indexOf('img') == -1) {
                this.setData({
                    typeTitle: 18
                })
            } else {
                this.setData({
                    typeTitle: 0
                })
            }
            this.setData({
                content: contents,
                title: title,
            })
        })
    },
    getBannerList(ids) {
        let id = ids
        request('index/bannerdetails', {
            data: {
                id
            }
        }).then(({
            data
        }) => {
            const {
                title,
                name,
                content
            } = data
            console.log(name);
            // wx.setNavigationBarTitle({
            //     title: name || '栏目详情'
            // })
            let zhengze = new RegExp('<img', 'g')
            if (content.indexOf('img') == -1) {
                this.setData({
                    typeTitle: 18
                })
            } else {
                this.setData({
                    typeTitle: 0
                })
            }
            let contents = content.replace(zhengze, '<img show-menu-by-longpress bindtap="previewImage" style="width:100%;height:auto;display:block;margin:10px 0;" ')
            console.log(contents);

            this.setData({
                content: contents,
                title: name ||  title || '栏目详情',
            })
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})